//
//  RGQuitLoginView.m
//  RedGrass
//
//  Created by wuyine on 2018/12/17.
//  Copyright © 2018年 hongcaosp. All rights reserved.
//

#import "RGQuitLoginView.h"

@implementation RGQuitLoginView

- (instancetype)init {
    if (self = [super init]) {
        self.backgroundColor = UICOLOR_WITH_RGBINT_A(0x000000, 0.5);
        UIView *contentView = [[UIView alloc] init];
        contentView.backgroundColor = UICOLOR_WITH_RGBINT(0xffffff);
        contentView.layer.cornerRadius = 10;
        [self addSubview:contentView];
        [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.mas_equalTo(0);
            make.size.mas_equalTo(CGSizeMake(300, 160));
        }];
        
        UILabel *title = [[UILabel alloc] init];
        title.textColor = UICOLOR_WITH_RGBINT(0x333333);
        title.font = FONT(customFontName, 18);
        title.text = @"温馨提示";
        
        UILabel *subTitle = [[UILabel alloc] init];
        subTitle.textColor = UICOLOR_WITH_RGBINT(0x666666);
        subTitle.font = FONT(customFontNameLight, 16);
        subTitle.text = @"确定退出当前账号？";
        
        UIButton *cancel = [UIButton buttonWithType:UIButtonTypeCustom];
        [cancel setTitleColor:UICOLOR_WITH_RGBINT(0x666666) forState:UIControlStateNormal];
        [cancel setTitle:@"取消" forState:UIControlStateNormal];
        cancel.titleLabel.font = FONT(customFontName, 17);
        [cancel addTarget:self action:@selector(cancel:) forControlEvents:UIControlEventTouchUpInside];
        
        UIButton *ensure = [UIButton buttonWithType:UIButtonTypeCustom];
        [ensure setTitleColor:UICOLOR_WITH_RGBINT(0xf73152) forState:UIControlStateNormal];
        [ensure setTitle:@"确定" forState:UIControlStateNormal];
        cancel.titleLabel.font = FONT(customFontName, 17);
        [ensure addTarget:self action:@selector(ensure:) forControlEvents:UIControlEventTouchUpInside];
        
        [contentView addSubview:title];
        [contentView addSubview:subTitle];
        [contentView addSubview:cancel];
        [contentView addSubview:ensure];
        
        [title mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(20);
            make.top.mas_equalTo(20);
            make.height.mas_equalTo(18);
        }];
        
        [subTitle mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(title.mas_leading);
            make.top.equalTo(title.mas_bottom).offset(25);
            make.height.mas_equalTo(16);
        }];
        
        [cancel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(0);
            make.top.equalTo(subTitle.mas_bottom).offset(5);
            make.bottom.mas_equalTo(0);
        }];
        
        [ensure mas_makeConstraints:^(MASConstraintMaker *make) {
            make.trailing.mas_equalTo(0);
            make.leading.equalTo(cancel.mas_trailing).offset(0);
            make.top.equalTo(subTitle.mas_bottom).offset(5);
            make.bottom.mas_equalTo(0);
            make.width.equalTo(cancel.mas_width);
        }];
    }
    return self;
}

- (void)cancel:(UIButton *)btn {
    [self removeFromSuperview];
}

- (void)ensure:(UIButton *)btn {
    if (self.quitLogin) {
        self.quitLogin();
    }
    [self removeFromSuperview];
}

- (void)showInView:(UIView *)view {
    [view addSubview:self];
    [self mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsZero);
    }];
}
@end
